package com.example.sgxs_api.controller;
import com.example.sgxs_api.domain.UserInfo;
import com.example.sgxs_api.mapper.UserInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin(origins = "*")
@Slf4j
@RestController
@RequestMapping("user")
public class UserInfoController {
    @Autowired
    private UserInfoMapper userMapper;

    /*
            登录
     */
    @GetMapping("login")
    public boolean login(@RequestParam("login") String account, @RequestParam("pwd") String password) {
        log.info("-----------------------------");
        log.info(account);
        log.info(password);
        if (userMapper.selectUser(account, password) == null) {
            return false;
        } else
            return true;
    }

    /*
            注册
     */
    @GetMapping("register")
    public boolean register(@RequestParam("login") String user_name, @RequestParam("pwd") String user_password, @RequestParam("pwd") String sex) {
        UserInfo user = userMapper.selectUserById(user_name);
        if (user != null) {
            return false;
        } else {
            int resultCount = userMapper.saveUser(user_name, user_password, sex);
            if (resultCount == 0) {
                return false;
            } else
                return true;
        }

    }

    /*
                  个人中心
     */

    @RequestMapping("look")
    private List<UserInfo> getALL() {
        List<UserInfo> list = userMapper.getAll();
        return list;

    }
}